import { Button, Space } from 'antd';
import {
  CheckCircleOutlined,
  ClockCircleOutlined,
  ExclamationCircleOutlined,
  FileTextOutlined,
  PlayCircleOutlined
} from '@ant-design/icons';
import type { SelectProps } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { getOptionLabel } from '../../data/statusData';

const columns = (onLogButtonClick: (record: any) => void, executeStatuses: SelectProps['options']) => {
  const columns: ColumnsType<any> = [
    {
      title: '计划时间',
      dataIndex: 'planTime',
      key: 'planTime',
      render: (text, record, index) => text ? text.substr(0, 10) : ''
    },
    {
      title: '执行序号',
      dataIndex: 'sequenceIndex',
      key: 'sequenceIndex',
      align: 'right'
    },
    {
      title: '开始时间',
      dataIndex: 'startTime',
      key: 'startTime'
    },
    {
      title: '结束时间',
      dataIndex: 'endTime',
      key: 'endTime'
    },
    {
      title: '执行状态',
      dataIndex: 'executeStatus',
      key: 'executeStatus',
      render: (text, record, index) => (
        <Space size={5}>
          {
            text === 'Created' ? (
              <ClockCircleOutlined style={{ color: 'rgba(0,0,0,0.45)' }} />
            ) : (text === 'Started' ? (
              <PlayCircleOutlined style={{ color: '#faad14' }} />
            ) : (text === 'Ended' ? (
              <CheckCircleOutlined style={{ color: '#52c41a' }} />
            ) : (text === 'Error' ? (
              <ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />
            ) : null)))
          }
          {getOptionLabel(executeStatuses, text)}
        </Space>
      )
    },
    {
      title: '日志',
      dataIndex: 'log',
      key: 'log',
      align: 'center',
      render: (text, record, index) => {
        return (
          <Button
            type="link"
            style={{ padding: 0 }}
            onClick={() => onLogButtonClick(record)}
          >
            <FileTextOutlined />
          </Button>
        );
      }
    }
  ];
  return columns;
};

export default columns;
